package com.spring.ioc.example;

import com.spring.ioc.example.dao.UserDaoImpl;
import com.spring.ioc.example.dao.UserDaoMySQL;
import com.spring.ioc.example.dao.UserDaoSQLServer;
import com.spring.ioc.example.service.UserService;
import com.spring.ioc.example.service.UserServiceImpl;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public class test {
    @Test
    public void testService(){
        //用户实际调用的是业务层,dao层他们不需要接触！
        UserServiceImpl userService = new UserServiceImpl();
        //userService.setUserDao(new UserDaoImpl());
        userService.setUserDao(new UserDaoSQLServer());
        userService.getUser();
    }

    @Test
    public void testSpring(){
        //获取, 拿到Spring的容器
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        //容器在手,天下我有,需要什么,就直接get什么
        UserServiceImpl userServiceImpl = (UserServiceImpl) context.getBean("UserServiceImpl");
        userServiceImpl.getUser();
    }
}
